package SiTuQingYou.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBHelper 
{
	//1
	private  DBHelper() {}
	//2
	private static  DBHelper db = new  DBHelper();
	//3
	public static  DBHelper getDB()
	{
		return db;
	}
	
	public Connection getConn()
	{
		Connection conn =null;
		try 
		{
		
			Class.forName("com.mysql.cj.jdbc.Driver");
			String url ="jdbc:mysql://cdb-5zh66scm.bj.tencentcdb.com:10077/travel?unicode=true&serverTimezone=Asia/Shanghai";
			
			conn = DriverManager.getConnection(url, "root", "situqingyou1");
			
			return conn;
		
		} 
		catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}
	
	//�ر�
	public void close(ResultSet rs,PreparedStatement ps,Connection conn)
	{
		if(rs!=null)
		{
			try 
			{
				rs.close();
			}
			catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(ps!=null)
		{
			try {
				ps.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if(conn!=null)
		{
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
